<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page pageEncoding="UTF-8"%>
<%
    // 如果已经登录，跳转到首页
    if (session.getAttribute("user") != null) {
        response.sendRedirect(request.getContextPath() + "/index.jsp");
        return;
    }
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户登录 - 购物网</title>
    <link rel="stylesheet" href="<%= request.getContextPath() %>/assets/css/styles.css">
    <style>
        .login-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: calc(100vh - 160px);
            padding: 2rem 0;
        }
        
        .login-card {
            width: 100%;
            max-width: 400px;
            border-radius: var(--border-radius-lg);
            box-shadow: var(--shadow-lg);
            background: var(--white-color);
            overflow: hidden;
            transition: var(--transition);
            animation: fadeInUp 0.6s ease-out;
        }
        
        .login-card:hover {
            box-shadow: var(--shadow-xl);
        }
        
        .login-header {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
            color: white;
            padding: 2rem 1.5rem;
            text-align: center;
        }
        
        .login-header h2 {
            margin: 0;
            font-size: 1.8rem;
            font-weight: 600;
        }
        
        .login-body {
            padding: 2rem 1.5rem;
        }
        
        .form-group {
            margin-bottom: 1.5rem;
            position: relative;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            color: var(--gray-700);
            font-weight: 500;
        }
        
        .form-control {
            width: 100%;
            padding: 0.75rem 1rem;
            border: 1px solid var(--gray-300);
            border-radius: var(--border-radius);
            font-size: 1rem;
            transition: var(--transition);
            background-color: var(--gray-50);
        }
        
        .form-control:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(66, 99, 235, 0.1);
            background-color: white;
        }
        
        .form-icon {
            position: absolute;
            right: 1rem;
            top: 70%;
            transform: translateY(-50%);
            color: var(--gray-400);
            pointer-events: none;
        }
        
        .login-actions {
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }
        
        .btn-login {
            width: 100%;
            padding: 0.75rem;
            font-size: 1.1rem;
            font-weight: 600;
            border: none;
            border-radius: var(--border-radius);
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
            color: white;
            cursor: pointer;
            transition: var(--transition);
            position: relative;
            overflow: hidden;
        }
        
        .btn-login::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
            transition: var(--transition);
        }
        
        .btn-login:hover::before {
            left: 100%;
        }
        
        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(66, 99, 235, 0.3);
        }
        
        .login-footer {
            text-align: center;
            padding: 1rem 0 2rem;
        }
        
        .login-footer a {
            color: var(--primary-color);
            text-decoration: none;
            font-weight: 500;
            transition: var(--transition);
        }
        
        .login-footer a:hover {
            color: var(--primary-dark);
            text-decoration: underline;
        }
        
        .login-footer p {
            margin: 0.75rem 0;
            color: var(--gray-600);
        }
        
        .separator {
            display: flex;
            align-items: center;
            margin: 1.5rem 0;
            color: var(--gray-400);
        }
        
        .separator::before,
        .separator::after {
            content: '';
            flex: 1;
            height: 1px;
            background: var(--gray-300);
        }
        
        .separator-text {
            padding: 0 1rem;
            font-size: 0.9rem;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="header-nav">
        <div class="nav-container">
            <a href="<%= request.getContextPath() %>/index.jsp" class="nav-brand">
                🛒 购物网
            </a>
            
            <ul class="nav-links">
                <li><a href="<%= request.getContextPath() %>/index.jsp">首页</a></li>
                <li><a href="<%= request.getContextPath() %>/products/list.jsp">商品浏览</a></li>
                <li><a href="<%= request.getContextPath() %>/cart/view/cart.jsp">购物车</a></li>
            </ul>
            <div class="user-actions">
                <a href="<%= request.getContextPath() %>/auth/login.jsp" class="btn btn-outline">登录</a>
                <a href="<%= request.getContextPath() %>/auth/register.jsp" class="btn" style="margin-left: 10px;">注册</a>
            </div>
        </div>
    </nav>
    
    <div class="container">
        <div class="login-container">
            <div class="login-card">
                <div class="login-header">
                    <h2>欢迎回来</h2>
                </div>
                
                <% if (request.getParameter("error") != null) { %>
                    <div class="alert alert-error">
                        <%= "invalid".equals(request.getParameter("error")) ? "用户名或密码错误!" : request.getParameter("error") %>
                    </div>
                <% } %>
                
                <% if (request.getParameter("registered") != null) { %>
                    <div class="alert alert-success">
                        注册成功，请登录！
                    </div>
                <% } %>
                
                <div class="login-body">
                    <form action="login_action.jsp" method="post">
                        <div class="form-group">
                            <label for="username">用户名:</label>
                            <input type="text" id="username" name="username" class="form-control" required autocomplete="username">
                            <span class="form-icon">👤</span>
                        </div>
                        
                        <div class="form-group">
                            <label for="password">密码:</label>
                            <input type="password" id="password" name="password" class="form-control" required autocomplete="current-password">
                            <span class="form-icon">🔒</span>
                        </div>
                        
                        <div class="login-actions">
                            <input type="submit" value="登录" class="btn-login">
                        </div>
                    </form>
                </div>
                
                <div class="login-footer">
                    <p>还没有账户? <a href="register.jsp">立即注册</a></p>
                    <p><a href="forgot_password.jsp">忘记密码?</a></p>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 页脚 -->
    <footer class="footer">
        <div class="container">
            <div class="footer-top">
                <div>
                    <a href="<%= request.getContextPath() %>/index.jsp" class="footer-logo">🛒 购物网</a>
                    <p style="margin-top: 1rem; color: var(--gray-400); font-size: 0.9rem;">
                        优质商品，优质服务，打造您的理想购物体验。
                    </p>
                </div>
                
                <div>
                    <h4 class="footer-heading">快速链接</h4>
                    <ul class="footer-links">
                        <li><a href="<%= request.getContextPath() %>/index.jsp">首页</a></li>
                        <li><a href="<%= request.getContextPath() %>/products/list.jsp">商品浏览</a></li>
                        <li><a href="#">关于我们</a></li>
                        <li><a href="#">联系我们</a></li>
                    </ul>
                </div>
                
                <div>
                    <h4 class="footer-heading">客户服务</h4>
                    <ul class="footer-links">
                        <li><a href="#">帮助中心</a></li>
                        <li><a href="#">售后政策</a></li>
                        <li><a href="#">配送信息</a></li>
                        <li><a href="#">常见问题</a></li>
                    </ul>
                </div>
            </div>
            
            <div class="footer-bottom">
                <p>&copy; 2025 购物网. 保留所有权利.</p>
            </div>
        </div>
    </footer>
</body>
</html>